<#assign base=request.contextPath />
<#if receivablesDO?? && (receivablesDO.id)!=0>
	<#assign leafLabel="编辑收款">
	<#else>
	<#assign leafLabel="新增收款">
</#if>
<!DOCTYPE html>
<html lang="en">
<head>
	<#include "/commons/headImport.ftl">
</head>
<body>
	<div class="main-container" id="main-container">
	<input type="hidden" value="${base}" id="context_hidden_id"/>
		<script type="text/javascript">
			try{ace.settings.check('main-container' , 'fixed')}catch(e){}
		</script>

		<div class="main-container-inner">
			<div class="main-content">
				<div class="page-content">
					<form class="form-horizontal" name="formName" method="post">
					<input type="hidden" value="${receivablesDO.contractId!0}" name="contractId" id="contractId"/>
					<input type="hidden" value="${receivablesDO.id!0}" name="id" id="id"/>
					
					<div class="row">
						<div class="col-xs-12">
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right">第</label>
								<div class="col-sm-3">
									<@spring.formInput "receivablesDO.periods" "class='col-sm-12'"/>
								</div>
								<div class="help-block col-xs-12 col-sm-reset inline">期</div>
							</div>
							<div class="space-4"></div>
								
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right">应收金额</label>
								<div class="col-sm-3">
									<@spring.formInput "receivablesDO.pageTotalAmount" "class='col-sm-12'"/>
								</div>
							</div>
							<div class="space-4"></div>
								
							<div class="form-group">
								<label class="col-sm-2 control-label no-padding-right">备注</label>
								<div class="col-sm-6">
									<@spring.formTextarea "receivablesDO.remark" "class='col-sm-10' rows='3'"/>
								</div>
							</div>
							<div class="space-4"></div>
						</div><!-- /.col -->
					</div><!-- /.row -->
					</form>
					
					<div class="hr hr32 hr-dotted"></div>
					
					<div class="clearfix">
						<label class="col-sm-2 control-label no-padding-right"></label>
						<div class="col-md-offset-3 col-md-9">
							<button class="btn btn-xs btn-info" type="button" id="add_id"
								url="<#if receivablesDO??&&receivablesDO.id!=0>${base}/receivables/edit<#else>${base}/receivables/add</#if>">
								<i class="icon-save bigger-110"></i>保存
							</button>
							<button class="btn btn-xs" type="reset" id="return_id">
								<i class="icon-reply bigger-110"></i>关闭
							</button>
						</div>
					</div>
					
				</div><!-- /.page-content -->
			</div><!-- /.main-content -->
		</div><!-- /.main-container-inner -->
	</div><!-- /.main-container -->
<#include "/commons/footJs.ftl">
<script src="${base}/static/layer/layer.js"></script>
<script type="text/javascript">
	jQuery(function($) {
		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
	
	   	$("#add_id").click(function(){
	   		var url=$(this).attr("url");
			var contractId=$("#contractId").val();
			var customerId=$("#customerId").val();
	   		var periods= $("#periods").val();
	   		var pageTotalAmount = $("#pageTotalAmount").val();
	   		var pageReceivedAmount=0;
	   		if(periods==""){
	   			layer.msg('期必须填写');
	   			return false;
	   		}
	   		if(pageTotalAmount==""||pageTotalAmount==0){
	   			layer.msg('应收金额必须填写,并大于0');
	   			return false;
	   		}
	   		layer.load(2);
			$.post(
				url, 
				{
				"id":$("#id").val(),
				"contractId": contractId,
				"customerId": customerId,
				"periods": periods,
				"pageTotalAmount":pageTotalAmount,
				"pageReceivedAmount":pageReceivedAmount,
				"remark":$("#remark").val()
				},
			  	function(data){
			     if(data.success){
			     	layer.closeAll('loading');
			     	parent.layer.close(index);
			     	window.parent.location.reload();
			     }else{
			     	var json = JSON.stringify(data.msg);
			     	layer.msg(json);
			     	layer.closeAll('loading');
			     }
			 });
	   	});
	   	
	   $("#return_id").click(function(){
			parent.layer.close(index);
	   });
	});
</script>
</body>
</html>
